package com.foruo.module.foruomoduleehcache;

import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestCacheController {

    /**
     * 获取缓存数据
     * 获取指定字典表具体行数据
     * @author GaoYuan
     * @date 2018/8/3 下午4:09
     */
    @Cacheable(value = "dict", key = "'dict_'+#dictCd+'_'+#dictItemCd")
    @GetMapping("get")
    public String get(String dictCd, String dictItemCd){
        System.out.println("没走缓存");
        if("1".equals(dictCd)){
            if("1".equals(dictItemCd)){
                return "1";
            }
            if("2".equals(dictItemCd)){
                return "2";
            }
        }
        return "123";
    }

    /**
     * 清除缓存
     * @author GaoYuan
     * @date 2018/8/3 下午4:10
     */
    @CacheEvict("dict")
    @GetMapping("clean")
    public String clean(){
        return "成功清除";
    }

    /**
     * 更新缓存
     * @author GaoYuan
     * @date 2018/8/3 下午4:10
     */
    @CachePut("dict")
    @GetMapping("update")
    public String update(){
        return "1234";
    }
}
